﻿using Core.Tools.Config;
using Core.Tools.IOC;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UI.Application.Config.Models;

namespace UI.Application.Config.Services
{
    /// <summary>
    /// 系统配置的管理者，管理整个系统的配置参数读写/保存
    /// </summary>
    [ExposedService(Lifttime.Singleton)]
    public class SystemConfigManager
    {
        public SystemConfigModel Config { get; private set; }
        private IConfigManager ConfigManager { get; }

        public SystemConfigManager(IConfigManager configManager)
        {
            ConfigManager = configManager;

            Config = ConfigManager.Read<SystemConfigModel>(ConfigKey.SystemConfig) ?? new SystemConfigModel();
        }

        public void Save(SystemConfigModel model)
        {
            ConfigManager.Write(ConfigKey.SystemConfig, model);
        }
    }
}
